#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAXN = 50007;
struct node {
    int x;
    LL len;
    node(int a, LL b) {x=a; len=b;}
    node() {}
};
vector<node> G[MAXN];
LL res = 0;
bool vis[MAXN];
int n,st;
void BFS() {
    queue<node> q;
    q.push(node(st, 0));
    vis[st]  = true;
    while(!q.empty()) {
        node pre = q.front(); q.pop();
        vector<node>& vec = G[pre.x];
        if (pre.len>res) res = pre.len;
        int len = vec.size();
        for (int i=0; i<len; ++i) {
            if (!vis[vec[i].x]) {
                vec[i].len += pre.len;
                vis[vec[i].x] = true;
                q.push(vec[i]);
            }
        }
    }
}

int main() {
    cin>>n>>st;
    int a, b, l;
    LL cnt = 0;
    for (int i=1; i<n; ++i) {
        scanf("%d %d %d", &a, &b, &l);
        cnt += l;
        G[a].push_back(node(b, l));
        G[b].push_back(node(a, l));
    }
    BFS();
    printf("%lld\n", 2*cnt-res);
    return 0;
}
